| Conditions | 3 |
| Total Lines | 89 |
| Code Lines | 77 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import { stopLocationUpdatesAsync } from 'expo-location'; |
||
| 7 | |||
| 8 | export default function Wallet({navigation}): any { |
||
| 9 | const [balance, setBalance] = useState(null); |
||
| 10 | const [modalVisible, setModalVisible] = useState(false); |
||
| 11 | const [prepaid, setPrepaid] = useState(null); |
||
| 12 | |||
| 13 | //Get balance for logged in user |
||
| 14 | useEffect(() => { |
||
| 15 | async function getBalance(): Promise<void> { |
||
| 16 | const result = await userModel.getBalance(); |
||
| 17 | setBalance(result); |
||
| 18 | |||
| 19 | }; |
||
| 20 | getBalance(); |
||
| 21 | }); |
||
| 22 | |||
| 23 | async function addBalance() { |
||
| 24 | setModalVisible(false); |
||
| 25 | const result = await userModel.addFunds(prepaid); |
||
| 26 | const updatedBalance = await userModel.getBalance(); |
||
| 27 | console.log(updatedBalance); |
||
| 28 | |||
| 29 | setBalance(updatedBalance); |
||
| 30 | }; |
||
| 31 | |||
| 32 | return ( |
||
| 33 | <View style={styles.container}> |
||
| 34 | |||
| 35 | |||
| 36 | <View style={[styles.infoContainer]}> |
||
| 37 | <Pressable style={[styles.backButton, styles.shadowProp]} onPress={() => navigation.navigate('Map')}> |
||
| 38 | <Icon |
||
| 39 | name='x' |
||
| 40 | size={25} |
||
| 41 | color='black' |
||
| 42 | /> |
||
| 43 | </Pressable> |
||
| 44 | |||
| 45 | <Text style={styles.title}>Your Balance</Text> |
||
| 46 | <Text style={styles.balance}>{balance} kr</Text> |
||
| 47 | <Text style={styles.info}>You should have at least SEK 30 in your wallet to start the journey</Text> |
||
| 48 | </View> |
||
| 49 | |||
| 50 | <View style={styles.prepaidContainer}> |
||
| 51 | <Text style={styles.prepaidInfo}>Use prepaid card to deposit money</Text> |
||
| 52 | <Pressable style={[styles.prepaidButton, styles.shadowProp]} onPress={() => setModalVisible(true)}> |
||
| 53 | <Text style={styles.buttonText} > Use prepaid card </Text> |
||
| 54 | </Pressable> |
||
| 55 | </View> |
||
| 56 | |||
| 57 | <Modal |
||
| 58 | animationType="slide" |
||
| 59 | transparent={true} |
||
| 60 | visible={modalVisible} |
||
| 61 | onRequestClose={() => { |
||
| 62 | setModalVisible(!modalVisible); |
||
| 63 | }} |
||
| 64 | > |
||
| 65 | <View style={styles.modalContainer}></View> |
||
| 66 | <View style={styles.modalMessage}> |
||
| 67 | |||
| 68 | <View style={styles.modalCloseContainer}> |
||
| 69 | |||
| 70 | <Pressable style={[styles.closeButton, styles.shadowProp]} onPress={() => setModalVisible(false)}> |
||
| 71 | <Icon |
||
| 72 | name='x' |
||
| 73 | size={15} |
||
| 74 | color='black' |
||
| 75 | /> |
||
| 76 | </Pressable> |
||
| 77 | |||
| 78 | </View> |
||
| 79 | |||
| 80 | <TextInput |
||
| 81 | placeholder="Enter prepaid card number" |
||
| 82 | style={styles.input} |
||
| 83 | keyboardType="email-address" |
||
| 84 | onChangeText={(content: string) => { |
||
| 85 | setPrepaid(content) |
||
| 86 | }} |
||
| 87 | |||
| 88 | onSubmitEditing={() => addBalance() |
||
| 89 | } |
||
| 90 | /> |
||
| 91 | </View> |
||
| 92 | </Modal> |
||
| 93 | |||
| 94 | |||
| 95 | </View> |
||
| 96 | ) |
||
| 229 | }); |